package DataLayer.Model;

import java.util.ArrayList;

/**
 * keeps info about: Ordre.
 * 
 * @author Gruppe 4 - Dennis Biil, Brian Smed, Kristian Henriksen og Anders Engbo
 * @version 1.0
 */
public class Ordre
{
	private int ordreId;
	private Long oprettelsesDato;
	private Long leveringsDato;
	private OrdreStatus ordreStatus;
	private String ordreType;
	private boolean directOnly;
	private double total;
	private double rabat;
	private double debit;
	private String note;
	private Kunde k;
	private ArrayList<DelOrdre> delo;

	/**
	 * Constructor
	 */
	public Ordre(
			Long oprettelsesDato, Long leveringsDato, OrdreStatus ordreStatus, String ordreType,
			boolean directOnly,
			double rabat, double total, double debit, String note, Kunde k,
			ArrayList<DelOrdre> delo)
	{
		this.oprettelsesDato = oprettelsesDato;
		this.leveringsDato = leveringsDato;
		this.ordreStatus = ordreStatus;
		this.ordreType = ordreType;
		this.directOnly = directOnly;
		this.total = total;
		this.rabat = rabat;
		this.debit = debit;
		this.note = note;
		this.k = k;
		this.delo = delo;
	}

	/**
	 * Empty constructor
	 */
	public Ordre()
	{
		this.delo = new ArrayList<DelOrdre>();
	}

	/**
	 * Set and get methods
	 */
	public int getOrdreId()
	{
		return ordreId;
	}

	public Kunde getKunde()
	{
		return k;
	}

	public void setKunde(Kunde k)
	{
		this.k = k;
	}

	public ArrayList<DelOrdre> getDelOrdre()
	{
		return delo;
	}

	public void setDelOrdre(ArrayList<DelOrdre> delo)
	{
		this.delo = delo;
	}

	public void setOrdreId(int ordreId)
	{
		this.ordreId = ordreId;
	}

	public Long getOprettelsesDato()
	{
		return oprettelsesDato;
	}

	public void setOprettelsesDato(Long oprettelsesDato)
	{
		this.oprettelsesDato = oprettelsesDato;
	}

	public Long getLeveringsDato()
	{
		return leveringsDato;
	}

	public void setLeveringsDato(Long leveringsDato)
	{
		this.leveringsDato = leveringsDato;
	}

	public OrdreStatus getOrdreStatus()
	{
		return ordreStatus;
	}

	public void setOrdreStatus(OrdreStatus ordreStatus)
	{
		this.ordreStatus = ordreStatus;
	}

	public String getOrdreType()
	{
		return ordreType;
	}

	public void setOrdreType(String ordreType)
	{
		this.ordreType = ordreType;
	}

	public boolean isDirectOnly()
	{
		return directOnly;
	}

	public void setDirectOnly(boolean directOnly)
	{
		this.directOnly = directOnly;
	}

	public double getDebit()
	{
		return debit;
	}

	public void setDebit(double d)
	{
		this.debit = d;
	}

	public double getRabat()
	{
		return rabat;
	}

	public void setRabat(double rabat)
	{
		this.rabat = rabat;
	}

	/**
	 * Calculates the Total price on and order, and minuses the discount
	 */
	public double getTotal()
	{
		if (!delo.isEmpty())
		{
			this.total = 0;
			for (DelOrdre d : getDelOrdre())
			{
				this.total += d.getDelTotal();
			}
			this.total -= this.rabat;
		}
		return this.total;
	}

	public void setTotal(double total)
	{
		this.total = total;
	}

	public String getNote()
	{
		return note;
	}

	public void setNote(String note)
	{
		this.note = note;
	}

	/**
	 * Sets the enum for which display Ordrestatus is to be used.
	 */
	public enum OrdreStatus
	{
		CREATED("Passiv"), ACTIVE("Aktiv"), ENDED("Afsluttet");
		private final String display;

		private OrdreStatus(String s)
		{
			display = s;
		}

		@Override
		public String toString()
		{
			return display;
		}
	};
}
